package com.lastproject.ejb.entities;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@NamedQuery(name = "Candidate.findAll", query = "SELECT c from Candidate c")
public class Candidate implements Serializable {

	/**
		 * 
		 */
	private static final long serialVersionUID = -4041978200822066983L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private int id;

	@OneToMany(mappedBy = "candidate")
	private List<Interview> interviews;

	private String firstname;
	private String lastname;
	
	@Temporal(TemporalType.DATE)
	private Date birthdate;
	private String applyingFor;
	private String domain;
	private String statut;
	private String phoneNr;
	private byte[] photo;	
	public void setPhoneNr(String phoneNr) {
		this.phoneNr = phoneNr;
	}

	private String email;

	@Lob
	private byte[] cv;

	public Candidate() {
	}
	
	public byte[] getPhoto() {
		return photo;
	}
	
	public void setPhoto(byte[] photo) {
		this.photo = photo;
	}

	public Candidate(int id, List<Interview> interviews, String firstname,
			String lastname, Date birthdate, String applyingFor, String domain,
			String statut, String phoneNr, String email, byte[] cv, byte[] photo) {
		super();
		this.id = id;
		this.interviews = interviews;
		this.firstname = firstname;
		this.lastname = lastname;
		this.birthdate = birthdate;
		this.applyingFor = applyingFor;
		this.domain = domain;
		this.statut = statut;
		this.phoneNr = phoneNr;
		this.email = email;
		this.cv = cv;
		this.photo = photo;
	}

	public List<Interview> getInterviews() {
		return interviews;
	}

	public void setInterviews(List<Interview> interviews) {
		this.interviews = interviews;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getFirstname() {
		return firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public String getLastname() {
		return lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public Date getBirthdate() {
		return birthdate;
	}

	public void setBirthdate(Date birthdate) {
		this.birthdate = birthdate;
	}

	public String getApplyingFor() {
		return applyingFor;
	}

	public void setApplyingFor(String applyingFor) {
		this.applyingFor = applyingFor;
	}

	public String getDomain() {
		return domain;
	}

	public void setDomain(String domain) {
		this.domain = domain;
	}

	public String getStatut() {
		return statut;
	}

	public void setStatut(String statut) {
		this.statut = statut;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public byte[] getCv() {
		return cv;
	}

	public void setCv(byte[] cv) {
		this.cv = cv;
	}



	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((applyingFor == null) ? 0 : applyingFor.hashCode());
		result = prime * result
				+ ((birthdate == null) ? 0 : birthdate.hashCode());
		result = prime * result + Arrays.hashCode(cv);
		result = prime * result + ((domain == null) ? 0 : domain.hashCode());
		result = prime * result + ((email == null) ? 0 : email.hashCode());
		result = prime * result
				+ ((firstname == null) ? 0 : firstname.hashCode());
		result = prime * result + id;
		result = prime * result
				+ ((interviews == null) ? 0 : interviews.hashCode());
		result = prime * result
				+ ((lastname == null) ? 0 : lastname.hashCode());
		result = prime * result + ((phoneNr == null) ? 0 : phoneNr.hashCode());
		result = prime * result + ((statut == null) ? 0 : statut.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Candidate other = (Candidate) obj;
		if (applyingFor == null) {
			if (other.applyingFor != null)
				return false;
		} else if (!applyingFor.equals(other.applyingFor))
			return false;
		if (birthdate == null) {
			if (other.birthdate != null)
				return false;
		} else if (!birthdate.equals(other.birthdate))
			return false;
		if (!Arrays.equals(cv, other.cv))
			return false;
		if (domain == null) {
			if (other.domain != null)
				return false;
		} else if (!domain.equals(other.domain))
			return false;
		if (email == null) {
			if (other.email != null)
				return false;
		} else if (!email.equals(other.email))
			return false;
		if (firstname == null) {
			if (other.firstname != null)
				return false;
		} else if (!firstname.equals(other.firstname))
			return false;
		if (id != other.id)
			return false;
		if (interviews == null) {
			if (other.interviews != null)
				return false;
		} else if (!interviews.equals(other.interviews))
			return false;
		if (lastname == null) {
			if (other.lastname != null)
				return false;
		} else if (!lastname.equals(other.lastname))
			return false;
		if (phoneNr == null) {
			if (other.phoneNr != null)
				return false;
		} else if (!phoneNr.equals(other.phoneNr))
			return false;
		if (statut == null) {
			if (other.statut != null)
				return false;
		} else if (!statut.equals(other.statut))
			return false;
		return true;
	}

	public String getPhoneNr() {
		return phoneNr;
	}

	@Override
	public String toString() {
		return "Candidate [id=" + id + ", interviews=" + interviews
				+ ", firstname=" + firstname + ", lastname=" + lastname
				+ ", birthdate=" + birthdate + ", applyingFor=" + applyingFor
				+ ", domain=" + domain + ", statut=" + statut + ", phoneNr="
				+ phoneNr + ", email=" + email + ", cv=" + Arrays.toString(cv)
				+ "]";
	}

}
